package cn.edu.neusoft.cqy917.zyfypt_cqy917.activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import cn.edu.neusoft.cqy917.zyfypt_cqy917.R;
import cn.edu.neusoft.cqy917.zyfypt_cqy917.iface.RegisterListener;
import cn.edu.neusoft.cqy917.zyfypt_cqy917.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity {
    TextView textView3;
    TextView textView4;
    TextView textView5;
    TextView textView6;
    TextView textView7;
    TextView textView8;
    TextView textView9;
    TextView textView10;
    EditText editText4;
    EditText editText5;
    EditText editText6;
    EditText editText7;
    EditText editText8;
    Button button3;
    Button button4;
    Button button5;
    RegisterListener registerListener =new RegisterListener() {
        @Override
        public void onResponse(String registermsg) {
            if (registermsg.contains("1")){
                Toast.makeText(RegisterActivity.this,"注册成功",
                        Toast.LENGTH_SHORT).show();
            }
            else if (registermsg.contains("已存在")){
                Toast.makeText(RegisterActivity.this,
                        "已存在",Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(RegisterActivity.this,
                        "注册失败",Toast.LENGTH_SHORT).show();

            }
        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        textView3 = (TextView) findViewById(R.id.textView3);
        textView4 = (TextView) findViewById(R.id.textView4);
        textView5 = (TextView) findViewById(R.id.textView5);
        textView6 = (TextView) findViewById(R.id.textView6);
        textView7 = (TextView) findViewById(R.id.textView7);
        textView8 = (TextView) findViewById(R.id.textView8);
        textView9 = (TextView) findViewById(R.id.textView9);
        textView10 = (TextView) findViewById(R.id.textView10);
        editText4 = (EditText) findViewById(R.id.editText4);
        editText5 = (EditText) findViewById(R.id.editText5);
        editText6 = (EditText) findViewById(R.id.editText6);
        editText7 = (EditText) findViewById(R.id.editText7);
        editText8 = (EditText) findViewById(R.id.editText8);
        button3 = (Button) findViewById(R.id.button3);
        button4 = (Button) findViewById(R.id.button4);
        button5 = (Button) findViewById(R.id.button5);
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username =editText8.getText().toString();
                String passwd   =editText4.getText().toString();
                String passwd2  =editText5.getText().toString();
                String realname =editText6.getText().toString();
                String tel  =  editText7.getText().toString();
                if (username.equals("")){
                    Toast.makeText(RegisterActivity.this, "用户名不能为空",
                            Toast.LENGTH_SHORT).show();
                    return;
                }
                if (!passwd.equals(passwd2)){
                    Toast.makeText(RegisterActivity.this, "密码不一致",
                            Toast.LENGTH_SHORT).show();
                    return;
                }
                RegisterModel registerModel =new RegisterModel();
                registerModel.getRegisterResult
                        (username,passwd,tel,registerListener);
            }

        });

        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
            }
        });
    }
}
